const express = require('express');
const router = express.Router();

// 路由中间件
const adminAuth = require('../middlewares/admin-auth');
const userAuth = require('../middlewares/user-auth');

// 后台路由文件
const adminArticlesRouter = require('../routes/admin/articles');
const adminCategoriesRouter = require('../routes/admin/categories');
const adminSettingsRouter = require('../routes/admin/settings');
const adminUsersRouter = require('../routes/admin/users');
const adminCoursesRouter = require('../routes/admin/courses');
const adminChaptersRouter = require('../routes/admin/chapters');
const adminChartsRouter = require('../routes/admin/charts');
const adminAuthRouter = require('../routes/admin/auth');
const adminAttachmentsRouter = require('../routes/admin/attachments');
const adminLogsRouter = require('../routes/admin/logs');
const adminMembershipsRouter = require('../routes/admin/memberships');
const adminOrdersRouter = require('../routes/admin/orders');

// 前台路由文件
const webHomeRouter = require('../routes/web/home');
const webCategoriesRouter = require('../routes/web/categories');
const webCoursesRouter = require('../routes/web/courses');
const webChaptersRouter = require('../routes/web/chapters');
const webArticlesRouter = require('../routes/web/articles');
const webSettingsRouter = require('../routes/web/settings');
const webAuthRouter = require('../routes/web/auth');
const webUsersRouter = require('../routes/web/users');
const webLikesRouter = require('../routes/web/likes');
const webCaptchaRouter = require('../routes/web/captcha');
const webMembershipsRouter = require('../routes/web/memberships');
const webOrdersRouter = require('../routes/web/orders');

// 文件上传
const uploadsRouter = require('../routes/uploads');
const mailRouter = require('../routes/mail');

// 支付宝路由
const webAlipayRouter = require('../routes/web/alipay');

// 后台路由配置
router.use('/admin/articles', adminAuth, adminArticlesRouter);
router.use('/admin/categories', adminAuth, adminCategoriesRouter);
router.use('/admin/settings', adminAuth, adminSettingsRouter);
router.use('/admin/users', adminAuth, adminUsersRouter);
router.use('/admin/courses', adminAuth, adminCoursesRouter);
router.use('/admin/chapters', adminAuth, adminChaptersRouter);
router.use('/admin/charts', adminAuth, adminChartsRouter);
router.use('/admin/auth', adminAuthRouter);
router.use('/admin/attachments', adminAuth, adminAttachmentsRouter);
router.use('/admin/logs', adminAuth, adminLogsRouter);
router.use('/admin/memberships', adminAuth, adminMembershipsRouter);
router.use('/admin/orders', adminAuth, adminOrdersRouter);

// 前台路由配置
router.use('/web/home', webHomeRouter);
router.use('/web/categories', webCategoriesRouter);
router.use('/web/courses', webCoursesRouter);
router.use('/web/chapters', userAuth, webChaptersRouter);
router.use('/web/articles', webArticlesRouter);
router.use('/web/settings', webSettingsRouter);
router.use('/web/auth', webAuthRouter);
router.use('/web/users', userAuth, webUsersRouter);
router.use('/web/likes', userAuth, webLikesRouter);
router.use('/web/orders', userAuth, webOrdersRouter);
router.use('/web/memberships', webMembershipsRouter);

// 验证码路由
router.use('/web/captcha', webCaptchaRouter);

// 文件上传路由
router.use('/uploads', userAuth, uploadsRouter);
router.use('/mail', userAuth, mailRouter);

// 支付宝路由
router.use('/web/alipay', webAlipayRouter);

module.exports = router;
